package com.cuitrip.component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

/**
 * Created by sheena on 15/12/23.
 */
public class AutoMatchListView extends ListView{

    private int startY;

    public AutoMatchListView(Context context) {
        super(context);
    }

    public AutoMatchListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AutoMatchListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                startY = (int) getY();
                break;

            case MotionEvent.ACTION_MOVE:
                float endY = getY();
                if(Math.abs(endY-startY)>5){
                    getParent().requestDisallowInterceptTouchEvent(false);
                }
                break;

            case MotionEvent.ACTION_UP:
                break;

        }
        return super.onInterceptTouchEvent(ev);
    }
}
